#import "Person.h"


@implementation Person
@synthesize firstName=_firstName;
@synthesize lastName=_lastName;
@synthesize middleName=_middleName;
@synthesize prefix=_prefix;
@synthesize suffix=_suffix;
@synthesize company=_company;
@synthesize jobTitle=_jobTitle;
@synthesize department=_department;
@synthesize email=_email;
@synthesize street=_street;
@synthesize city=_city;
@synthesize state=_state;
@synthesize zip=_zip;
@synthesize country=_country;
@synthesize mobile=_mobile;
@synthesize workPhone=_workPhone;
@synthesize workFax=_workFax;
@synthesize homeFax=_homeFax;
@synthesize homePhone=_homePhone;
@synthesize workPager=_workPager;
@synthesize personURL=_personURL;
@synthesize UNID=_UNID;
@synthesize birthday=_birthday;
@synthesize updatedInDatabase=_updatedInDatabase;

- (Person*)init{
	_firstName=@"";
	_lastName=@"";
	_middleName=@"";
	_prefix=@"";
	_suffix=@"";
	_company=@"";
	_jobTitle=@"";
	_department=@"";
	_email=@"";
	_birthday=@"";
	_street=@"";
	 _city=@"";
	_state=@"";
	_zip=@"";
	_country=@"";
	_mobile=@"";
	_workPhone=@"";
	_homeFax=@"";
	_homePhone=@"";
	_workFax=@"";
	_workPager=@"";
	_personURL=@"";	
	_updatedInDatabase=NO;
	return self;
}



//This function is to produce the content to display in the contact content view. 
- (NSArray *)detailInformationArray
{
	NSMutableArray* array=[[NSMutableArray alloc] init];
	NSMutableString* nameField=[[NSMutableString alloc] init];
	if(![self isNilAttribute:_prefix])
		[nameField appendFormat:@"%@ ", _prefix];
	if(![self isNilAttribute:_firstName])
		[nameField appendFormat:@"%@ ", _firstName];
	if(![self isNilAttribute:_middleName])
		[nameField appendFormat:@"%@ ", _middleName];
	if(![self isNilAttribute:_lastName])
		[nameField appendFormat:@"%@ ", _lastName];
	if(![self isNilAttribute:_suffix])
		[nameField appendFormat:@"%@", _suffix];
	if([self isNilAttribute:nameField])
		[nameField setString:@"N/A"];
	[array addObject:nameField];
	[nameField release];
	if(![self isNilAttribute:_email])
		[array addObject:[NSString stringWithFormat:@"Email: %@", _email]];
	if(![self isNilAttribute:_mobile])
		[array addObject:[NSString stringWithFormat:@"Mobile: %@", _mobile]];
	if(![self isNilAttribute:_jobTitle])
		[array addObject:[NSString stringWithFormat:@"JobTitle: %@", _jobTitle]];
	if(![self isNilAttribute:_department])
		[array addObject:[NSString stringWithFormat:@"Department: %@", _department]];
	if(![self isNilAttribute:_company])
		[array addObject:[NSString stringWithFormat:@"Company: %@", _company]];	
	if(![self isNilAttribute:_street])
		[array addObject:[NSString stringWithFormat:@"Street: %@", _street]];
	if(![self isNilAttribute:_city])
		[array addObject:[NSString stringWithFormat:@"City: %@", _city]];
	if(![self isNilAttribute:_state])
		[array addObject:[NSString stringWithFormat:@"State: %@", _state]];
	if(![self isNilAttribute:_country])
		[array addObject:[NSString stringWithFormat:@"Country: %@", _country]];
	if(![self isNilAttribute:_zip])
		[array addObject:[NSString stringWithFormat:@"Zip Code: %@", _zip]];
	if(![self isNilAttribute:_workPhone])
		[array addObject:[NSString stringWithFormat:@"Work Phone: %@", _workPhone]];
	if(![self isNilAttribute:_workFax])
		[array addObject:[NSString stringWithFormat:@"Work Fax: %@", _workFax]];
	if(![self isNilAttribute:_workPager])
		[array addObject:[NSString stringWithFormat:@"Work Pager: %@", _workPager]];
	if(![self isNilAttribute:_homePhone])
		[array addObject:[NSString stringWithFormat:@"Home Phone: %@", _homePhone]];
	if(![self isNilAttribute:_homeFax])
		[array addObject:[NSString stringWithFormat:@"Home Fax: %@", _homeFax]];
	if(![self isNilAttribute:_personURL])
		[array addObject:[NSString stringWithFormat:@"Personal URL: %@", _personURL]];
	if(![self isNilAttribute:_birthday])
		[array addObject:[NSString stringWithFormat:@"Birthday: %@", _birthday]];
	return [array autorelease];
}


//Uitility function to test if given string is not nil or empty
- (BOOL)isNilAttribute:(NSString *)testString{
	if(testString ==nil || [testString isEqualToString:@""])
		return YES;
	else{
		NSRange range;
		while((range=[testString rangeOfString:@"\n"]).location!=NSNotFound)
			testString=[testString substringToIndex:range.location];
		if([testString isEqualToString:@""])
			return YES;
		return NO;
	}
}

/*
 <input name="tmpOfficeAddress" type="hidden" value="llo">
 <input name="tmpHomeAddress" type="hidden" value="">
 <input name="DisplayName" type="hidden" value="allan lf">
 <input name="DisplayJobTitle" type="hidden" value="llo">
 <input name="DisplayCompanyName" type="hidden" value="lolo">
 <input name="DisplayAddress" type="hidden" value=" lolo    lool">
 <input name="FirstName" type="hidden" value="allan">
 <input name="PhoneLabel1" type="hidden" value="Office phone">
 <input name="OfficePhoneNumber" type="hidden" value="vzxc">
 <input name="MiddleInitial" type="hidden" value="a">
 
 <input name="PhoneLabel3" type="hidden" value="Office fax">
 <input name="OfficeFAXPhoneNumber" type="hidden" value="ewqr">
 <input name="LastName" type="hidden" value="lf">
 <input name="PhoneLabel5" type="hidden" value="Cell phone">
 <input name="CellPhoneNumber" type="hidden" value="">
 <input name="Title" type="hidden" value="Mr.">
 <input name="Suffix" type="hidden" value="Jr.">
 <input name="PhoneLabel2" type="hidden" value="Home phone">
 <input name="PhoneNumber" type="hidden" value="">
 <input name="Category" type="hidden" value="N">
 <input name="PhoneLabel4" type="hidden" value="Home fax">
 <input name="HomeFAXPhoneNumber" type="hidden" value="">
 <input name="PhoneLabel6" type="hidden" value="Pager">
 <input name="PhoneNumber_6" type="hidden" value="bhsd">
 <input name="CompanyName" type="hidden" value="lolo">
 <input name="MailAddress" type="hidden" value="dsafasd">
 <input name="JobTitle" type="hidden" value="llo">
 
 <input name="WebSite" type="hidden" value="loloio">
 <input name="OfficeStreetAddress" type="hidden" value="llo">
 <input name="StreetAddress" type="hidden" value="">
 <input name="OfficeCity" type="hidden" value="lolo">
 <input name="City" type="hidden" value="">
 <input name="OfficeState" type="hidden" value="lolo">
 <input name="State" type="hidden" value="">
 <input name="OfficeZip" type="hidden" value="lolo">
 <input name="Zip" type="hidden" value="">
 <input name="OfficeCountry" type="hidden" value="lool">
 <input name="Country" type="hidden" value="">
 <input name="Location" type="hidden" value="">
 <input name="Spouse" type="hidden" value="">
 <input name="Department" type="hidden" value="lolo">
 <input name="Children" type="hidden" value="">
 <input name="Manager" type="hidden" value="">
 <input name="Assistant" type="hidden" value="lolo">
 
 <input name="Birthday" type="hidden" value="">
 <input name="path" type="hidden" value="mail/eye.nsf">
 <input name="ExcludeFromView" type="hidden" value="A, D">
 <input name="$NoPurge" type="hidden" value="1">
 <input name="ProtectFromArchive" type="hidden" value="1">
 */
@end
